package com.sgcc.ln.pmos.e_ln_home.dialog;

import android.content.Context;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.lxj.xpopup.core.BottomPopupView;
import com.sgcc.pmos.nativesdk.R;

/**
 * @author ChaoAJ
 * @describe 市场行情日期选择
 * @time 2022/8/29 14:10
 */
public class DateSelectDialog extends BottomPopupView {
    String[] strings;
    ItemClickListener itemClickListener;

    public DateSelectDialog(Context context, String[] strings, ItemClickListener itemClickListener) {
        super(context);
        this.strings = strings;
        this.itemClickListener = itemClickListener;
    }


    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_date_select_layout;
    }


    @Override
    protected void onCreate() {
        super.onCreate();
        findViewById(R.id.tvCancel).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });

        findViewById(R.id.tvDetermine).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        ListView listView = findViewById(R.id.listview);

        listView.setAdapter(new ArrayAdapter<String>(getContext(),
               R.layout.item,
                strings));

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                String result = ((TextView) view).getText().toString();
                if (null != itemClickListener)
                    itemClickListener.onClick(result, i);
                dismiss();
            }
        });


    }


    @Override
    protected void onShow() {
        super.onShow();
    }

    @Override
    protected void onDismiss() {
        super.onDismiss();
    }


    public interface ItemClickListener {

        void onClick(String text, int position);

    }


}